@isTest
private class MeasureCalcPreControllerTest {
    // 测试画面逻辑
    static testMethod void testMethod1() {
        Province__c pro = TestUtils.createProvince();
        insert pro;

        City__c c = TestUtils.createCity();
        c.Province__c = pro.Id;
        insert c;

        District__c d = TestUtils.createDistrict();
        d.City__c = c.Id;
        insert d;

        // 客户
        Account acc = TestUtils.createAccount();
        acc.Province__c = pro.Id;
        acc.City__c = c.Id;
        acc.District__c = d.Id;
        insert acc;

        Department__c dt1=[select id,hospitalDepartments__c,TerminalCustomer__c from Department__c where 
        hospitalDepartments__c='检验科' and TerminalCustomer__c=:acc.Id limit 1];
        dt1.LastYearRevenue__c=123;
        dt1.PurchasingCost__c = 11;
        update dt1;

        // 业务机会
        Opportunity opp = TestUtils.createOpportunity();
        opp.AccountId = acc.Id;
        opp.StageCanChange__c = '意向';
        opp.StageName = '意向';
        opp.CooperationMode__c= '整体配送';
        insert opp;

    //创建产品

        Product__c p = TestUtils.createInst();
        p.Purpose__c = '仪器报价用';
        p.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        p.Category0__c= '仪器';

        insert p;

    //创建意向产品

        IntentProduct__c ip = TestUtils.createIntentProduct();
        ip.Opportunity__c = opp.Id;
        ip.Product__c = p.Id;
        insert ip;

        //联系人补充
        Contact con1 = TestUtils.createContact();
        con1.LastName = '测试采购科';
        con1.AccountId = acc.Id;
        insert con1;

        Contact con2 = TestUtils.createContact();
        con2.LastName = '测试分管院长';
        con2.Post__c = '分管院长(设备)';
        con2.Departments__c = '医院办公室';
        con2.AccountId = acc.Id;
        insert con2;

        Contact con3 = TestUtils.createContact();
        con3.LastName = '测试财务';
        con3.Post__c = '科长/主任';
        con3.Departments__c = '财务科/计财处';
        con3.AccountId = acc.Id;
        insert con3;

        Contact con4 = TestUtils.createContact();
        con4.LastName = '测试检验';
        con4.Post__c = '科长/主任';
        con4.Departments__c = '检验科';
        con4.AccountId = acc.Id;
        insert con4;

        Account acc1 = TestUtils.createAccount();
        acc1.name = '迈克实业测试';
        acc1.Province__c = pro.Id;
        acc1.City__c = c.Id;
        acc1.District__c = d.Id;
        acc1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('Maccura','Account');
        insert acc1;
        // opp.StageCanChange__c = '方案谈判';
        opp.StageName = '立项';
        opp.ExecuteCompany__c = acc1.Id;
        opp.ExecutiveCompany__c = acc1.Id;
        update opp;
        

        opp.StageCanChange__c = '立项';
        update opp;

        Test.startTest();

        // ---------------------新建-----------------------
        PageReference page = new PageReference('/apex/MeasureCalcPre?oppid=' + opp.Id);
        System.Test.setCurrentPage(page);
        MeasureCalcPreController qc = new MeasureCalcPreController(new ApexPages.StandardController(new Measure_Calculate__c()));

        qc.init();
        //System.debug(qc.mcpbList);
        qc.qpList[0].chk = true;
        qc.exchange();
        qc.mcpbList[0].mcp.CoopType__c = '投放';
        qc.mc.AdditionalService__c = '施工图制作;效果图制作;';

        qc.save();
        Measure_Calculate__c mc = new Measure_Calculate__c(
            Opportunity__c = opp.Id,
            Company__c = '四川省迈克实业有限公司'
        );
        insert mc;


        Measure_Calculate_Product__c mcp = new Measure_Calculate_Product__c(
            Measure_Calculate__c = mc.Id,
            Product__c = p.Id
        );
        insert mcp;

        mc.Status__c = '审批成功';
        update mc;


        qc.init();
        qc.qpList[0].chk = true;
        qc.exchange();


        qc.save();



       
   // ---------------------编辑-----------------------
        page = new PageReference('/apex/MeasureCalcPre?id=' + mc.Id);
        System.Test.setCurrentPage(page);
        qc = new MeasureCalcPreController(new ApexPages.StandardController(mc));
        qc.init();
        qc.save();
    }
/*
   // 测试审批通过
   static testMethod void testMethod2() {
        Province__c pro = TestUtils.createProvince();
        insert pro;

        City__c c = TestUtils.createCity();
        c.Province__c = pro.Id;
        insert c;

        District__c d = TestUtils.createDistrict();
        d.City__c = c.Id;
        insert d;

        Product__c p = TestUtils.createProduct();
        insert p;

        // 客户
        Account acc = TestUtils.createAccount();
        acc.Province__c = pro.Id;
        acc.City__c = c.Id;
        acc.District__c = d.Id;
        insert acc;
        Department__c dt1=[select id,hospitalDepartments__c,TerminalCustomer__c from Department__c where 
        hospitalDepartments__c='检验科' and TerminalCustomer__c=:acc.Id limit 1];
        dt1.LastYearRevenue__c=123;
        update dt1;

        // 业务机会
        Opportunity opp = TestUtils.createOpportunity();
        opp.AccountId = acc.Id;
        opp.StageCanChange__c = '意向';
        opp.StageName = '意向';
        insert opp;

        IntentProduct__c ip = TestUtils.createIntentProduct();
        ip.Opportunity__c = opp.Id;
        insert ip;

        //联系人补充
        Contact con1 = TestUtils.createContact();
        con1.LastName = '测试采购科';
        con1.AccountId = acc.Id;
        insert con1;

        Contact con2 = TestUtils.createContact();
        con2.LastName = '测试分管院长';
        con2.Post__c = '分管院长(设备)';
        con2.Departments__c = '医院办公室';
        con2.AccountId = acc.Id;
        insert con2;

        Contact con3 = TestUtils.createContact();
        con3.LastName = '测试财务';
        con3.Post__c = '科长/主任';
        con3.Departments__c = '财务科/计财处';
        con3.AccountId = acc.Id;
        insert con3;

        Contact con4 = TestUtils.createContact();
        con4.LastName = '测试检验';
        con4.Post__c = '科长/主任';
        con4.Departments__c = '检验科';
        con4.AccountId = acc.Id;
        insert con4;
        
 		Account acc1 = TestUtils.createAccount();
        acc1.name = '迈克实业测试';
        acc1.Province__c = pro.Id;
        acc1.City__c = c.Id;
        acc1.District__c = d.Id;
        acc1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('Maccura','Account');
        insert acc1;
        // opp.StageCanChange__c = '方案谈判';
        opp.StageName = '立项';
        opp.ExecuteCompany__c = acc1.Id;
        opp.ExecutiveCompany__c = acc1.Id;
        update opp;

        opp.StageCanChange__c = '立项';
        update opp;

        // 报价
        Quote q1 = new Quote(Name = 'test',  OpportunityId = opp.Id);
        Quote q2 = new Quote(Name = 'test2',  OpportunityId = opp.Id);
        insert new Quote[] {q1, q2};
        // insert q;
        Test.startTest();

        Measure_Calculate__c mc = new Measure_Calculate__c(
            
            Opportunity__c = opp.Id,

        );
        insert mc;

        Measure_Calculate_Product__c mcp = new Measure_Calculate_Product__c(
            Measure_Calculate__c = mc.Id,
            Product__c = p.Id
        );
        insert mcp;

        mc.Status__c = '审批成功';
        update mc;

    }
    */
}